package com.hqbzl.chat.message;

import com.hqbzl.chat.protocol.MessageType;
import lombok.*;

import java.io.Serializable;

import static com.hqbzl.chat.constant.Constants.RPC_RESPONSE_MSG_TYPE;

@Builder
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class RpcResponseMessage implements MessageType, Serializable {

    private Object object;
    private Integer sequenceId;
    private Exception exception;
    private Class returnType;

    public static RpcResponseMessage buildSucc(Integer sequenceId, Object object) {
        return builder().sequenceId(sequenceId).object(object).build();
    }

    public static RpcResponseMessage buildFail(Integer sequenceId, Exception exception) {
        return builder().sequenceId(sequenceId).exception(exception).build();
    }

    @Override
    public int getMessageType() {
        return RPC_RESPONSE_MSG_TYPE;
    }

    @Override
    public int getSequenceId() {
        return this.sequenceId;
    }

}
